<?php

declare(strict_types=1);

namespace Plugin\Attractions\Commerce\Model\Commerce_order;

use Hyperf\Database\Model\SoftDeletes;
use Hyperf\DbConnection\Model\Model;
use Plugin\Attractions\Commerce\Model\Commerce_merchant\CommerceMerchant;
use Plugin\Attractions\Commerce\Model\Commerce_order_product\CommerceOrderProduct;

/**
 * @property int $id 订单号
 * @property int $merchant_id 商户ID
 * @property int $customer_id 客户ID
 * @property string $customer_name 客户姓名
 * @property string $customer_phone 客户电话
 * @property string $customer_address 客户地址
 * @property int $order_source 订单来源：1-线上下单，2-现场订单
 * @property string $total_amount 订单总金额
 * @property string $discount_amount 折扣优惠金额
 * @property string $minus_amount 满减优惠金额
 * @property string $actual_amount 实付金额
 * @property int $payment_method 付款方式1-银行转账,2-微信支付,3-支付宝支付,4-现金,5-其他付款方式
 * @property string $payment_time 支付时间
 * @property string $delivery_time 发货时间
 * @property string $express_company 快递公司
 * @property string $express_id 快递单号
 * @property string $express_cost 快递费用
 * @property array $express_info 快递信息
 * @property int $order_status 订单状态：1-未支付，2-已支付，3-已发货，4-已到货，5-已完成，6-已取消
 * @property string $cancel_reason 取消原因
 * @property string $cancel_time 取消时间
 * @property string $finish_time 完成时间
 * @property string $remark 备注
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property string $deleted_at 
 */
class CommerceOrder extends Model
{
    const  UNPAID = 1;
    const  PAID = 2;
    const  SHIPPED = 3;
    const  FINISHED = 4;
    const  CANCELED = 5;
    const  DELETED = 6;
    use SoftDeletes;
    public bool $incrementing = false;
    protected string $primaryKey = 'id';
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'commerce_order';

    protected array $hidden = ['deleted_at'];

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'merchant_id', 'customer_id', 'customer_name', 'customer_phone', 'customer_address', 'order_source', 'total_amount', 'discount_amount', 'minus_amount', 'actual_amount', 'payment_method', 'payment_time', 'delivery_time', 'express_company', 'express_id', 'express_cost', 'express_info', 'order_status', 'cancel_reason', 'cancel_time', 'finish_time', 'remark', 'created_at', 'updated_at', 'deleted_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'merchant_id' => 'integer', 'customer_id' => 'integer', 'order_source' => 'integer', 'total_amount' => 'decimal:2', 'discount_amount' => 'string', 'minus_amount' => 'string', 'actual_amount' => 'decimal:2', 'payment_method' => 'integer', 'express_info' => 'array', 'express_cost' => 'decimal:2', 'order_status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function commdities()
    {
        return $this->hasMany(CommerceOrderProduct::class, 'order_id', 'id');
    }

    public function merchant()
    {
        return $this->belongsTo(CommerceMerchant::class, 'merchant_id', 'id');
    }
}
